package com.zw.cc.stock.service.policy.kdj;

import com.zw.cc.stock.common.PolicyTypeEnum;
import com.zw.cc.stock.model.QuotesPo;
import com.zw.cc.stock.model.dto.KDJPolicyDto;
import com.zw.cc.stock.service.policy.CalculateService;
import com.zw.cc.stock.util.calculateutil;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * KDJ 卖出信号
 * Created by zhaowuz on 2018/1/11
 */
@Service
public class KDJBuySignal implements CalculateService<List<QuotesPo>> {

    private float offset = 1.1f; //值越大 CCI上涨角度越大

    private int offset2 = 10;

    private int lowest = 50;

    @Override
    public boolean calculate(List<QuotesPo> quotesPos) {
        List<KDJPolicyDto> kdjPolicyDtos = calculateutil.calKDJList(quotesPos);
        Collections.reverse(kdjPolicyDtos);
        KDJPolicyDto today = kdjPolicyDtos.get(0);
        KDJPolicyDto yesterday = kdjPolicyDtos.get(1);
        return today.getJ() > lowest  //今天在高位
                && yesterday.getJ()/today.getJ()>offset //下降趋势
                && yesterday.getJ()-yesterday.getD()>offset2; //
    }

    @Override
    public PolicyTypeEnum getType() {
        return PolicyTypeEnum.KDJ_SURPASS_SELLING;
    }
}
